############################################
###### Replication Code for Table A3  ######
########### January 9th, 2025 ##############
############################################

rm(list=ls())

### Script produces Table A3 save it in the `/tables` folder respectively

# load libraries
library(modelsummary)

# load main data
df <- readRDS("data/workfile.rds")

factor_levels <- unique(df$parfam_name) %>% sort()

# model 1: What determines immigration discussion?
m1 <- lm(open_immig ~ dem_age + 
        household_income + 
        dem_gender + 
          dem_rural +
        dem_education_level + 
        mean_outparty_feeling + 
        mean_close_num + 
     lrscale  + parfam_name + high_pol_interest + 
       as.factor(dem_country_code) + 
       treated_culture,
   df %>% filter(control == 0)) %>% summary()
m1

# model 2: What determines immigration discussion? + inparty
m2 <- lm(open_immig ~ dem_age + 
           household_income + 
           dem_gender + 
           in_party_feeling +
           dem_rural +
           dem_education_level + 
           mean_outparty_feeling + 
           mean_close_num + 
           lrscale  + parfam_name + high_pol_interest + 
           as.factor(dem_country_code) + 
           treated_culture,
         df %>% filter(control == 0)) %>% summary()

models_list = list("(1)" = m1, "(2)" = m2)

modelsummary(models_list, stars = T)
modelsummary(models_list, stars = T, 
             coef_omit = "dem_country_code*",
             title = "Predicting responses mentioning immigration",
             coef_rename = c("household_incomelow" = "Low HH inc", 
                             "household_incomemedium" = "Medium HH inc",
                             "household_incomePrefer not to say" = "HH inc missing",
                             "mean_outparty_feeling" = "Average Out-Party Feeling",
                             "dem_age" = "Age", 
                             "mean_close_num" = "Average Out-Party Social Distance",
                             "age_sq" = "Age squared",
                             "dem_gendermale" = "Male",
                             "dem_education_levellow" = "Low education", 
                             "dem_education_levelmedium" = "Medium education",
                             "dem_education_levelno" = "No education", 
                             "dem_rural" = "Rural",
                             "lrscale" = "Left-right scale",
                             "treated_culture" = "Cultural issues condition", 
                             "political_interest_num" = "Political Interest (1-5)",
                             "high_pol_interest" = "High political interest"),
             add_rows = data.frame(t(c("Country-FE included", "yes", "yes"))),
             output = "tables/TabA3_immig_DV.docx")
